package com.ynny.Dao;

import com.ynny.Dao.CourseManagerDao;
import com.ynny.Entity.Courses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class Courselmpl implements CourseManagerDao{
    @Autowired
    private jdbcTemplate jdbcTemplate;
    @Override
    public int updateCourse(String courseName) {
        String sql = "update courses set AD=AD+1 where courseName=?";
        return jdbcTemplate.update(sql,courseName);
    }
    @Override
    public List<Courses> queryCourse() {
        String sql = "select * from courses";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Courses.class));
    }
    @Override
    public Courses queryCourseByName(String courseName) {
        String sql = "select * from courses where courseName=?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Courses.class),courseName);
    }
}
